import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:share_plus/share_plus.dart';

/// https://pub.flutter-io.cn/packages/share
class ShareLibDemo extends StatelessWidget {
  final picker = ImagePicker();

  @override
  Widget build(BuildContext context) {
    var items = {
      '分享文本': () {
        Share.share("你好，我好，大家好");
      },
      '分享文件': () async {
        var image = await picker.pickImage(source: ImageSource.gallery);
        if (image != null) {
          // Share.shareFiles([image.path]);
          SharePlus.instance.share(new ShareParams(uri: Uri.file(image.path)));
        }
      },
      '': () {},
    };

    return Scaffold(
      appBar: AppBar(
        title: Text('ShareLibDemo'),
      ),
      body: ListView.separated(
        itemBuilder: (context, position) {
          var item = items.entries.elementAt(position);
          return ListTile(
            title: Text(item.key),
            onTap: item.value,
          );
        },
        itemCount: items.length,
        separatorBuilder: (context, position) => Divider(
          height: 1,
        ),
      ),
    );
  }
}